package com.spbdx.common.utils.sms.pojo;

import com.spbdx.common.utils.sms.support.MD5;

import java.util.List;

/**
 * Description 天翼云信短信
 *
 * @author chenwei
 * @version 1.0
 * @date 2023/1/13 14:11
 */
public class SendSmsEntity {
    String appKey = "";
    String timestamp = "";
    String mobile = "";
    String content = "";
    String sendTime = "";
    String spNumber = "";
    String sign = "";
    String reportUrl = "";
    String moUrl = "";
    String attach = "";

    public String getAppKey() {
        return appKey;
    }

    public void setAppKey(String appKey) {
        this.appKey = appKey;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getSendTime() {
        return sendTime;
    }

    public void setSendTime(String sendTime) {
        this.sendTime = sendTime;
    }

    public String getSpNumber() {
        return spNumber;
    }

    public void setSpNumber(String spNumber) {
        this.spNumber = spNumber;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public String getReportUrl() {
        return reportUrl;
    }

    public void setReportUrl(String reportUrl) {
        this.reportUrl = reportUrl;
    }

    public String getMoUrl() {
        return moUrl;
    }

    public void setMoUrl(String moUrl) {
        this.moUrl = moUrl;
    }

    public String getAttach() {
        return attach;
    }

    public void setAttach(String attach) {
        this.attach = attach;
    }

    @Override
    public String toString() {
        return String.format(
                "SendSmsEntity [appKey=%s, timestamp=%s, mobile=%s, content=%s, sendTime=%s, spNumber=%s, sign=%s, reportUrl=%s, moUrl=%s, attach=%s]",
                appKey, timestamp, mobile, content, sendTime, spNumber, sign, reportUrl, moUrl, attach);
    }

    /**
     * 构建发送内容
     *
     * @param mobiles
     * @param appKey
     * @param appSecret
     * @param content
     * @param reportUrl
     * @return
     */
    public static SendSmsEntity buildSendEntity(List<String> mobiles, String appKey, String appSecret, String content, String reportUrl) {
        SendSmsEntity entity = new SendSmsEntity();
        entity.setAppKey(appKey);
        entity.setTimestamp(System.currentTimeMillis() + "");
        entity.setMobile(String.join(",", mobiles));
        entity.setContent(content);
        entity.setReportUrl(reportUrl);
        entity.setSpNumber("");
        //签名校验必填写字段
        //appKey,timestamp,mobile,content,spNumber,sendTime,appSecret
        String source = entity.getAppKey() + entity.getTimestamp() + entity.getMobile() + entity.getContent()
                + entity.getSpNumber() + entity.getSendTime() + appSecret;
        String sign = MD5.getMD5(source);
        entity.setSign(sign);
        return entity;
    }
}
